<?php

namespace App\Modules\Admin\Entities\Water;
use App\Models\Model;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Relations\HasOne;

class ApparatusWaterRateModel extends Model
{
    protected $table = 'apparatus_water_rate';
    protected $fillable = [
        'apparatus_id',
        'price',
        'type',
        'started_at',
        'ended_at'
    ];

    /**
     * @param $value
     * @return string
     */
    public function getStartedAtAttribute($value): string
    {
        $date = Carbon::parse($value);
        return $date->format('Y年m月d日');
    }

    /**
     * @param $value
     * @return string
     */
    public function getEndedAtAttribute($value): string
    {
        $date = Carbon::parse($value);
        return $date->format('Y年m月d日');
    }
    /**
     *  电费 log
     * @return HasOne
     */
    public function waterRateLogInfo(): HasOne
    {
        return $this->hasOne(ApparatusWaterRateLogModel::class, 'id', 'apparatus_id');
    }
}
